package org.geekbang.bigdata.rpc;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;
import org.geekbang.bigdata.rpc.protocol.MyProtocol;
import org.geekbang.bigdata.rpc.protocol.MyProtocolImpl;

import java.io.IOException;

public class Server {

    public static void main(String[] args) {
        RPC.Builder builder = new RPC.Builder(new Configuration());
        // 服务器IP地址
        builder.setBindAddress("127.0.0.1");
        // 端口号
        builder.setPort(12345);

        builder.setProtocol(MyProtocol.class);
        builder.setInstance(new MyProtocolImpl());

        try {
            RPC.Server server = builder.build();
            server.start();
            System.out.println("Hadoop RPC Server started.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
